package testcase.doctor;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import api.doctor.GetChatMessageLast;
import common.Host;
import common.TestData;

/**
 * 帮忙医医生端获取历史聊天消息接口GetChatMessageLast测试用例
 * @author gaowen
 *
 */
public class TestGetChatMessageLast
{
	/**
	 * 帮忙医医生端获取历史聊天消息接口GetChatMessageLast测试环境数据驱动
	 * @return 测试数据
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 * @throws IOException
	 */
	@DataProvider(name="Test")
	public static String[][] testGetChatMessageLastDataProvider() throws ParserConfigurationException, SAXException, IOException
	{
		Host.setup("Test");
		TestData tData=new TestData("doctor/TestGetChatMessageLast.xml");
		return tData.getParam();
	}
	
	/**
	 * 帮忙医医生端获取历史聊天消息接口GetChatMessageLast测试环境测试用例
	 * @param caseName 用例名
	 * @param userID 用户ID
	 * @param ResponseID 医生ID
	 * @param token 调接口需要的token
	 * @throws JSONException 
	 * @throws IOException 
	 */
	@Test(dataProvider="Test",groups="Test")
	public void testGetChatMessageLastTestCase(String caseName,String userID,String ResponseID,String token) throws JSONException, IOException
	{
		String result=GetChatMessageLast.get(userID, ResponseID, token);
		
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (caseName)
		{
			case "Success":
				Assert.assertNotNull(jsonResult.getString("Data"));
				break;
			case "UserIDWrong":
				Assert.assertNotNull(jsonResult.getString("Data"));
				break;
			case "UserIDNull":
				Assert.assertNull(result);
				break;
			case "ResponseIDWrong":
				Assert.assertNotNull(jsonResult.getString("Data"));
				break;
			case "ResponseIDNull":
				Assert.assertNull(result);
				break;
			case "TokenWrong":
				Assert.assertNotNull(jsonResult.getString("Data"));
				break;
			case "TokenNull":
				Assert.assertNotNull(jsonResult.getString("Data"));
				break;
			default:
				break;
		}
	}
}
